#################################################
#
# Makefile frammento 1 progetto lcs09
#
#################################################

# ***** DA COMPLETARE ******  con i file da consegnare
FILE_DA_CONSEGNARE=./ptree.c ./intervals.c ./ilist.c


# Compiler flags
CFLAGS = -Wall -pedantic -g 


# Compilatore
CC = gcc


# Librerie
LIBDIR = ../lib
LIBS = -L $(LIBDIR)

# Nome libreria
LIBNAME = libztl.a

# Lista degli object files (** DA COMPLETARE ***)
OBJS = intervals.o ptree.o ilist.o test-libztl.o

# nome eseguibile
exe = prova

# phony targets
.PHONY: clean testiniziale lib test1 test2 docu consegna

# creazione libreria
lib:  $(OBJS)
	-rm  -f $(LIBDIR)/$(LIBNAME)
	ar -r $(LIBNAME) $(OBJS)
	cp $(LIBNAME) $(LIBDIR)

# eseguibile di test iniziale
$(exe): $(OBJS)
	$(CC) -o $@ $^ 

# dipendenze oggetto main di test
test-libztl.o: test-libztl.c intervals.h ptree.h ilist.h
	$(CC) $(CFLAGS) -c $<

# make rule per gli altri .o (***DA COMPLETARE***)



########### NON MODIFICARE DA QUA IN POI ################
# genera la documentazione con doxygen
docu: ../Doc/Doxyfile
	make -C ../Doc

#ripulisce
clean:
	-rm -f *.o *.~

# test con main iniziale
testiniziale: 
	make clean
	make $(exe)
	echo MALLOC_TRACE e\' $(MALLOC_TRACE)
	@echo MALLOC_TRACE deve essere settata a \"./.mtrace\"
	-rm -f ./.mtrace
	./$(exe)
	mtrace ./$(exe) ./.mtrace
	@echo -e "\a\n\t\t *** Test iniziale superato! ***\n"

# test unitario intervalli
test1:
	make clean
	make lib
	make -C ../Test/Test1 clean
	make -C ../Test/Test1 test
	@echo -e "\a\n\t\t *** Test unitario (1) intervalli superato! ***\n"

# test unitario alberi
test2:
	make clean
	make lib
	make -C ../Test/Test2 clean
	make -C ../Test/Test2 test
	@echo -e "\a\n\t\t *** Test unitario (2) ptree superato! ***\n"


# target di consegna
SUBJECT1="lcs09: consegna primo frammento"
consegna: 
	make testiniziale
	make test1
	make test2
	./gruppo-check.pl < gruppo.txt
	tar -cvf $(USER)-f1.tar ./gruppo.txt ./Makefile $(FILE_DA_CONSEGNARE)
	mpack -s $(SUBJECT1) ./$(USER)-f1.tar  susanna@di.unipi.it
	@echo -e "\a\n\t\t *** Frammento 1 consegnato  ***\n"
